<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for service\BollService.ts</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">all files</a> / <a href="index.html">service/</a> BollService.ts
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">100% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>53/53</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">94.44% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>17/18</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">100% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>5/5</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">100% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>52/52</span>
      </div>
    </div>
  </div>
  <div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-yes">116×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-yes">116×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">42×</span>
<span class="cline-any cline-yes">13×</span>
<span class="cline-any cline-yes">13×</span>
<span class="cline-any cline-yes">13×</span>
<span class="cline-any cline-yes">13×</span>
<span class="cline-any cline-yes">13×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">29×</span>
<span class="cline-any cline-yes">29×</span>
<span class="cline-any cline-yes">29×</span>
<span class="cline-any cline-yes">29×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">3×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { Injectable } from '@angular/core';
&nbsp;
import { QuoteBasic } from 'service/QuoteBasic';
import { IBollService } from 'interface/IBollService';
&nbsp;
@Injectable()
export class BollService implements IBollService {
&nbsp;
  connection;
&nbsp;
  constructor() {
&nbsp;
  }
&nbsp;
  private _cacuBoll(quote:QuoteBasic, day, k, start, end) {
    let ma = 0;
    let up = 0;
    let down = 0;
&nbsp;
    let maSum = 0;
&nbsp;
    for(let j=start; j&lt;=end; j++) {
      maSum+=quote.close[j];
    }
&nbsp;
    ma = parseFloat((maSum/(end-start+1)).toFixed(4));
&nbsp;
    let mdSum = 0;
    for(let j=start; j&lt;=end; j++) {
      mdSum += Math.pow(quote.close[j] - ma, 2);
    }
&nbsp;
    let md = Math.sqrt(mdSum/(end-start+1));
&nbsp;
    up = parseFloat((ma + k*md).toFixed(4));
    down = parseFloat((ma - k*md).toFixed(4));
&nbsp;
    return [ma, up, down];
  }
&nbsp;
  compute(quote:QuoteBasic, day:number, k:number):Array&lt;any&gt; {
    const mbList = [];
    const upList = [];
    const downList = [];
&nbsp;
    if(day&gt;0 &amp;&amp; k&gt;0){
        const count = quote.close.length;
        for(let i=0; i&lt;count; i++) {
          if(i &lt; day) {
            const data = this._cacuBoll(quote, day, k, 0, i);
            mbList.push(data[0]);
            upList.push(data[1]);
            downList.push(data[2]);
            continue;
          }
&nbsp;
          const data = this._cacuBoll(quote, day, k, i-day+1, i);
          mbList.push(data[0]);
          upList.push(data[1]);
          downList.push(data[2]);
        }
    }
    return [mbList, upList, downList];
  }
&nbsp;
  update(quote:QuoteBasic, day:number, k:number, mdList:Array&lt;any&gt;, upList:Array&lt;any&gt;, downList:Array&lt;any&gt;):Array&lt;any&gt; {
    const originCount = quote.close.length;
    const oldCount = mdList.length;
&nbsp;
    if(originCount &gt; 0 &amp;&amp; day &gt; 0) {
      if(oldCount === 0){
        return this.compute(quote, day, k);
      }
&nbsp;
      const start = (originCount - day) &lt; 0 ? 0 : (originCount - day);
      const end = (originCount - 1) &lt; 0 ? <span class="branch-0 cbranch-no" title="branch not covered" >0 </span>: (originCount - 1);
&nbsp;
      const temp = this._cacuBoll(quote, day, k, start, end);
&nbsp;
      if (oldCount &lt; originCount) {
        mdList.push(temp[0]);
        upList.push(temp[1]);
        downList.push(temp[2]);
      } else {
        mdList[end] = temp[0];
        upList[end] = temp[1];
        downList[end] = temp[2];
      }
    }
    return [mdList, upList, downList];
  }
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Jul 24 2017 16:45:57 GMT+0800 (中国标准时间)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
